package com.website.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.util.UUID;

public class MessageUtil {
 
 
	/**
	 * 随机翻译一个唯一的身份id
	 * @return
	 */
	public static String getOpenId(){
		UUID uuid = UUID.randomUUID();
		String openId = uuid.toString().replaceAll("-", "");
		return openId;
	}
	
 
	
	
	/**
	 * 返回复购不同的时间
	 * @param time
	 */
	public static String paserRepeateBuyingUtcTime(String time){
		int count = 24*60*60*5;
		int min = (int)(Math.random()*count);
		if(min < 24*60*60){
			min = 24*60*60;
		}
		Date date = null;
		SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
		df1.setTimeZone(TimeZone.getTimeZone("GMT"));
		try{
			date = df1.parse(time);
		}catch (ParseException e){
			e.printStackTrace();
		}
		Calendar ca = Calendar.getInstance();
		ca.setTime(date);
		ca.add(Calendar.SECOND,min);
		String returndate = df1.format(ca.getTime());
		return returndate;
	}
	
	/**
	 * 返回不同的时间
	 * @param time
	 */
	public static String paserUtcTime(String time,int i){
		int mintime = 1*60+i*65;
		Date date = null;
		SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
		df1.setTimeZone(TimeZone.getTimeZone("GMT"));
		try{
			date = df1.parse(time);
		}catch (ParseException e){
			e.printStackTrace();
		}
		Calendar ca = Calendar.getInstance();
		ca.setTime(date);
		ca.add(Calendar.SECOND,mintime);
		String returndate = df1.format(ca.getTime());
		return returndate;
	}
	
	
	/**
	 * 返回不同的时间
	 * @param time
	 */
	public static String paserUtcTime2(String time){
		int mintime = 1*84;
		Date date = null;
		SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
		df1.setTimeZone(TimeZone.getTimeZone("GMT"));
		try{
			date = df1.parse(time);
		}catch (ParseException e){
			e.printStackTrace();
		}
		Calendar ca = Calendar.getInstance();
		ca.setTime(date);
		ca.add(Calendar.SECOND,mintime);
		String returndate = df1.format(ca.getTime());
		return returndate;
	}
}
